package xgenerator.ui.swing;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.Toolkit;

import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
 * <p>
 * Title：AboutDialog
 * </p>
 * <p>
 * Description：
 * </p>
 * <p>
 * Copyright: Copyright (c) 2012
 * </p>
 * <p>
 * Company: liss
 * </p>
 * @author <a href="mailto:shushanlee@msn.com">liss</a>
 * @version 1.0
 * @see 
 * @since 1.0
 */
public class AboutDialog extends JDialog implements UIConstants {

	/**
	 * constructor
	 * @param owner
	 * @param title
	 * @param modal
	 */
	public AboutDialog(Frame owner, String title, boolean modal) {
		super(owner, title, modal);
		initComponents();
	}
	
	/**
	 * <p>
	 * Title：初始化组件
	 * </p>
	 * @author <a href="mailto:shushanlee@msn.com">liss</a>
	 */
	private void initComponents() {
		this.setTitle("关于XGenerator");
		this.setIconImage(IconUtils.createIconImage(APP_ICON_IMAGE));
		this.setContentPane(buildContentPane());

		Toolkit tk = Toolkit.getDefaultToolkit();
		Dimension screenSize = tk.getScreenSize();
		int screenHeight = screenSize.height;
		int screenWidth = screenSize.width;
		this.setSize(screenWidth / 3, screenHeight / 3);
		this.setLocation((screenWidth - getWidth()) / 2, (screenHeight - getHeight()) / 2);
		this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		this.setVisible(true);
	}
	
	/**
	 * <p>
	 * Title：
	 * </p>
	 * @return
	 */
	private JPanel buildContentPane() {
		JPanel panel = new JPanel();
		panel.setLayout(new BorderLayout());
		
		JLabel logoLabel = new JLabel(IconUtils.createImageIcon(IMAGE_CLASS_PATH + "cooltext669328171.png"), JLabel.LEFT);
		panel.add(logoLabel, BorderLayout.NORTH);
		panel.add(buildCenterPane(), BorderLayout.CENTER);

		return panel;
	}
	
	private JPanel buildCenterPane() {
		JPanel panel = new JPanel();
		panel.setLayout(new GridLayout(8, 2));
		
		JLabel versionLabel = new JLabel("版本：1.0.0.0");
		JLabel authorLabel = new JLabel("作者：李树山");
		JLabel msnLabel = new JLabel(IconUtils.createImageIcon(IMAGE_CLASS_PATH + "msncom.gif"), JLabel.LEFT);
		
		panel.add(versionLabel);
		panel.add(authorLabel);
		panel.add(msnLabel);

		return panel;
	}
	
}
